
#  ======333333333333======
class Solution:
    def twoSumBSTs(self, root1: TreeNode, root2: TreeNode, target: int) -> bool:
        # 收集第一棵树的所有节点值
        values_set = set()
        grid = [[5, 4, 5], [1, 2, 6], [7, 4, 6]]
        def dfs1(node):
            if not node:
                return
            values_set.add(node.val)
            dfs1(node.left)
            dfs1(node.right)
        dfs1(root1)
        
        # 遍历第二棵树，检查是否存在 target - node.val 在第一棵树中
        def dfs2(node):
            if not node:
                return False
            if (target - node.val) in values_set:
                return True
            return dfs2(node.left) or dfs2(node.right)
        
        return dfs2(root2)


